

//firefox and IE both OK like function insertAdjacentHTML
function insertHtml(where, el, html){
	where = where.toLowerCase();
	if(el.insertAdjacentHTML){
		switch(where){
			case "beforebegin":
                el.insertAdjacentHTML('BeforeBegin', html);
                return el.previousSibling;
            case "afterbegin":
                el.insertAdjacentHTML('AfterBegin', html);
                return el.firstChild;
            case "beforeend":
                el.insertAdjacentHTML('BeforeEnd', html);
                return el.lastChild;
            case "afterend":
                el.insertAdjacentHTML('AfterEnd', html);
                return el.nextSibling;
        }
        throw 'Illegal insertion point -> "' + where + '"';
    }
 	var range = el.ownerDocument.createRange();
    var frag;
    switch(where){
         case "beforebegin":
            range.setStartBefore(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el);
            return el.previousSibling;
         case "afterbegin":
            if(el.firstChild){
                range.setStartBefore(el.firstChild);
                frag = range.createContextualFragment(html);
                el.insertBefore(frag, el.firstChild);
                return el.firstChild;
            }else{
                el.innerHTML = html;
                return el.firstChild;
         	}
        case "beforeend":
            if(el.lastChild){
                range.setStartAfter(el.lastChild);
                frag = range.createContextualFragment(html);
                el.appendChild(frag);
                return el.lastChild;
            }else{
                el.innerHTML = html;
                return el.lastChild;
            }
        case "afterend":
            range.setStartAfter(el);
            frag = range.createContextualFragment(html);
            el.parentNode.insertBefore(frag, el.nextSibling);
            return el.nextSibling;
        }
        throw 'Illegal insertion point -> "' + where + '"';
}
/**
* weblord工程中javascript应用的工具包
* @author zhenwenxue
*/
/**
* 判断浏览器类型
*/
var browserType1 = 1;
var browserType2 = 2;
var browserType3 = 3;
var browserType4 = 4;
var browserType;
var browserVersion;
(function () {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf("opera") != -1) {
		browserType = browserType4;
	} else {
		if (userAgent.indexOf("safari") != -1) {
			browserType = browserType2;
		} else {
			if (userAgent.indexOf("msie") != -1) {
				browserType = browserType1;
				browserVersion = userAgent.substring(30, 33);
			} else {
				browserType = browserType3;
			}
		}
	}
})();
/**
* @description	parseDate	将value转换成日期
*/
function parseDate(value) {
	var date = null;
	if (Date.prototype.isPrototypeOf(value)) {
		date = value;
	} else {
		if (typeof (value) == "string") {
			date = new Date(value.replace(/-/g, "/"));
		}
	}
	return Date;
}
/**
* @description	parseTime	将value转换成"-"形式
*/
function parseTime(value) {
	var date = null;
	if (Date.prototype.isPrototypeOf(value)) {
		date = value;
	} else {
		if (typeof (value) == "string") {
			date = new Date("1970/01/01 " + value.replace(/-/g, "/"));
		}
	}
	return Date;
}
/**
* @description	parseBoolean	将value转换成布尔型
*/
function parseBoolean(value) {
	if (typeof (value) == "string") {
		return (value == "true");
	} else {
		if (typeof (value) == "boolean") {
			return value;
		} else {
			return (value != null);
		}
	}
}
/**
* @description	parseString	将value转换成字符串
*/
function parseString(value) {
	if (value == null) {
		return "";
	} else {
		return value.toString();
	}
}
if (typeof (Array.prototype.push) == "undefined") {
	Array.prototype.push = function (spacialObj) {
		this[this.length] = spacialObj;
	};
}
if (typeof (Array.prototype.indexOf) == "undefined") {
	Array.prototype.indexOf = function (spacialObj) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == spacialObj) {
				return i;
			}
		}
		return -1;
	};
}
if (typeof (Object.prototype.idd) == "undefined") {
	Object.prototype.idd = null;
}
/**
* @description	addId	实现自加
*/
var m = 10000;
function addId() {
	return "" + (m++);
}
/**
* @description	Element	初始化元素
*/
function Element(data) {
	this.previous = null;
	this.priviousElement = null;
	this.Data = data;
}
Element.prototype.getPrevious = function () {
	return this.previous;
};
Element.prototype.getNext = function () {
	return this.priviousElement;
};
Element.prototype.getData = function () {
	return this.Data;
};
Element.prototype.setData = function (data) {
	this.Data = data;
};
/**
* @description	Collection	初始化集合
*/
function Collection() {
	this.uObject = new Object();
	this.firstNode = null;
	this.lastNode = null;
	this.collectionSize = 0;
}
Collection.prototype.getFirst = function () {
	return this.firstNode;
};
Collection.prototype.getLast = function () {
	return this.lastNode;
};
Collection.prototype.size = function () {
	return this.collectionSize;
};
Collection.prototype.setObjectToArray = function (spacialObj) {
	var data = spacialObj.Data;
	var objId = null;
	if (data != null) {
		objId = data.idd;
	}
	if (objId != null) {
		this.uObject[objId] = spacialObj;
	}
};
Collection.prototype.removeObjectFormArray = function (spacialObj) {
	var data = spacialObj.Data;
	var objId = null;
	if (data != null) {
		objId = data.idd;
	}
	if (objId != null) {
		delete this.uObject[objId];
	}
};
Collection.prototype.createNewObject = function () {
	this.uObject = new Object();
};
/**
* @description	insertElement	向集合中插入元素
*/
Collection.prototype.insertElement = function (spacialObj, $h, Element00) {
	var previousElement, nextElement;
	switch ($h) {
	  case "begin":
		previousElement = null;
		nextElement = this.firstNode;
		break;
	  case "before":
		previousElement = (Element00) ? Element00.previous : null;
		nextElement = Element00;
		break;
	  case "after":
		previousElement = Element00;
		nextElement = (Element00) ? Element00.priviousElement : null;
		break;
	  default:
		previousElement = this.lastNode;
		nextElement = null;
		break;
	}
	spacialObj.previous = previousElement;
	spacialObj.priviousElement = nextElement;
	if (previousElement) {
		previousElement.priviousElement = spacialObj;
	} else {
		this.firstNode = spacialObj;
	}
	if (nextElement) {
		nextElement.previous = spacialObj;
	} else {
		this.lastNode = spacialObj;
	}
	this.setObjectToArray(spacialObj);
	this.collectionSize++;
};
/**
* @description	removeElement	从集合中删除元素
*/
Collection.prototype.removeElement = function (spacialObj) {
	var previousElement, nextElement;
	previousElement = spacialObj.previous;
	nextElement = spacialObj.priviousElement;
	if (previousElement) {
		previousElement.priviousElement = nextElement;
	} else {
		this.firstNode = nextElement;
	}
	if (nextElement) {
		nextElement.previous = previousElement;
	} else {
		this.lastNode = previousElement;
	}
	this.removeObjectFormArray(spacialObj);
	this.collectionSize--;
};
/**
* @description	insertCollection	向集合中插入子集合
*/
Collection.prototype.insertCollection = function (ElementCollection, $h, Element00) {
	if (!ElementCollection || !ElementCollection.firstNode) {
		return;
	}
	var previousElement, nextElement;
	switch ($h) {
	  case "begin":
		previousElement = null;
		nextElement = this.firstNode;
		break;
	  case "before":
		previousElement = (Element00) ? Element00.previous : null;
		nextElement = Element00;
		break;
	  case "after":
		previousElement = Element00;
		nextElement = (Element00) ? Element00.priviousElement : null;
		break;
	  default:
		previousElement = this.lastNode;
		nextElement = null;
		break;
	}
	var spacialObj = ElementCollection.firstNode;
	while (spacialObj) {
		this.setObjectToArray(spacialObj);
		spacialObj = spacialObj.priviousElement;
	}
	ElementCollection.firstNode.previous = previousElement;
	ElementCollection.lastNode.priviousElement = nextElement;
	if (previousElement) {
		previousElement.priviousElement = ElementCollection.firstNode;
	} else {
		this.firstNode = ElementCollection.firstNode;
	}
	if (nextElement) {
		nextElement.previous = ElementCollection.lastNode;
	} else {
		this.lastNode = ElementCollection.lastNode;
	}
	this.collectionSize += ElementCollection.collectionSize;
};
/**
* @description	clear	清除集合
*/
Collection.prototype.clear = function () {
	var spacialObj = this.firstNode;
	while (spacialObj) {
		if (spacialObj.Data) {
			delete spacialObj.Data;
		}
		spacialObj = spacialObj.priviousElement;
	}
	this.createNewObject();
	this.firstNode = null;
	this.lastNode = null;
	this.collectionSize = 0;
};
/**
* @description	findElement	查询元素
*/
Collection.prototype.findElement = function (data) {
	if (data == null) {
		return null;
	}
	var objId = data.idd;
	if (objId != null) {
		return this.uObject[objId];
	} else {
		var spacialObj = this.firstNode;
		while (spacialObj) {
			if (spacialObj.Data == data) {
				return spacialObj;
			}
			spacialObj = spacialObj.priviousElement;
		}
	}
};
/**
* @description	insert	插入元素
*/
Collection.prototype.insert = function (data, $h, Element01) {
	var Element00 = null;
	if (Element01 != null) {
		Element00 = this.findElement(Element01);
	}
	var spacialObj = new Element(data);
	this.insertElement(spacialObj, $h, Element00);
};
Collection.prototype.remove = function (data) {
	var spacialObj = this.findElement(data);
	if (spacialObj != null) {
		this.removeElement(spacialObj);
	}
};
/**
* @description	iterator	迭代输出集合
*/
Collection.prototype.iterator = function () {
	return new Iterator(this);
};
/**
* @description	toArray	将集合转换成数组
*/
Collection.prototype.toArray = function () {
	var uArray2 = new Array();
	var spacialObj = this.firstNode;
	while (spacialObj != null) {
		uArray2.push(spacialObj.Data);
		spacialObj = spacialObj.priviousElement;
	}
	return uArray2;
};
/**
* @description	Iterator   迭代器初始化
*/
function Iterator(dataContructure) {
	this.dataclec = dataContructure;
	this.$lV = true;
	this.Last = false;
	this.specialRecord = null;
}
Iterator.prototype.initcl1ec1 = function () {
	this.First = true;
	this.Last = false;
	this.specialRecord = null;
};
Iterator.prototype.initcl1ec2 = function () {
	this.First = false;
	this.Last = true;
	this.specialRecord = null;
};
Iterator.prototype.isFirst = function () {
	return this.First;
};
Iterator.prototype.isLast = function () {
	return this.Last;
};
/**
* @description	hasNext   判断下一条数据是否存在
*/
Iterator.prototype.hasNext = function () {
	if (this.First) {
		return (this.dataclec.firstNode != null);
	} else {
		if (this.specialRecord != null) {
			return (this.specialRecord.priviousElement != null);
		} else {
			return false;
		}
	}
};
/**
* @description	hasPrevious   判断前一条数据是否存在
*/
Iterator.prototype.hasPrevious = function () {
	if (this.Last) {
		return (this.dataclec.lastNode != null);
	} else {
		if (this.specialRecord != null) {
			return (this.specialRecord.previous != null);
		} else {
			return false;
		}
	}
};
/**
* @description	next   向后迭代输出
*/
Iterator.prototype.next = function () {
	var record06 = this.specialRecord;
	if (this.First) {
		record06 = this.dataclec.firstNode;
	} else {
		if (record06 != null) {
			record06 = record06.priviousElement;
		} else {
			record06 = null;
		}
	}
	this.specialRecord = record06;
	this.First = false;
	if (record06 != null) {
		this.Last = false;
		return record06.getData();
	} else {
		this.Last = true;
		return null;
	}
};
/**
* @description	previous  向前迭代输出
*/
Iterator.prototype.previous = function () {
	var record06 = this.specialRecord;
	if (this.Last) {
		record06 = this.dataclec.lastNode;
	} else {
		if (specialRecord != null) {
			record06 = record06.previous;
		} else {
			record06 = null;
		}
	}
	this.specialRecord = record06;
	this.Last = false;
	if (record06 != null) {
		this.First = false;
		return record06.getData();
	} else {
		this.First = true;
		return null;
	}
};
/**
* @description	HashList  初始化哈希表
*/
function HashList() {
	this.uArray3 = new Array();
	this.uObject = new Object();
}
/**
* @description	put  向哈希表添加数据
*/
HashList.prototype.put = function (key, spacialObj) {
	var hashArray = this.uArray3;
	var uObject3 = this.uObject;
	var uObject2 = uObject3[key];
	if (typeof (uObject2) == "undefined") {
		hashArray.push(spacialObj);
	} else {
		var i = hashArray.indexOf(uObject2);
		if (i >= 0) {
			hashArray[i] = spacialObj;
		}
	}
	uObject3[key] = spacialObj;
	spacialObj.key = key;
};
/**
* @description	get  从哈希表取出数据
*/
HashList.prototype.get = function (key) {
	if (typeof (key) == "number") {
		return this.uArray3[key];
	} else {
		return this.uObject[key];
	}
};
/**
* @description	indexOf  返回特定值
*/
HashList.prototype.indexOf = function (key) {
	var uObject2 = this.uObject[key];
	if (uObject2 != null) {
		return this.uArray3.indexOf(uObject2);
	} else {
		return -1;
	}
};
/**
* @description	remove  从哈希表中移出特定值
*/
HashList.prototype.remove = function (key) {
	var hashArray = this.uArray3;
	var uObject3 = this.uObject;
	var uObject2 = null;
	if (typeof (key) == "number") {
		uObject2 = hashArray[key];
		hashArray.splice(key, 1);
		delete uObject3[uObject2.key];
	} else {
		uObject2 = uObject3[key];
		delete uObject3[key];
		var i = hashArray.indexOf(uObject2);
		if (i >= 0) {
			hashArray.splice(i, 1);
		}
	}
	return uObject2;
};
/**
* @description	clear  清除哈希表
*/
HashList.prototype.clear = function () {
	this.uArray3 = new Array();
	this.uObject = new Object();
};
/**
* @description	size  哈希表的大小
*/
HashList.prototype.size = function () {
	return this.uArray3.length;
};
/**
* @description	ObjectPool  对象池
*/
var uArray4 = new Array();
function ObjectPool(whichComponent) {
	this.WhichComponent = whichComponent;
	this.map01Size = 0;
	this.map02Size = 0;
	this.uMap01 = new HashList();
	this.uMap02 = new HashList();
	uArray4.push(this);
}
/**
* @description	borrowObject 移出对象
*/
ObjectPool.prototype.borrowObject = function () {
	var spacialObj = null;
	if (this.map01Size > 0) {
		spacialObj = this.uMap01.uArray3.pop();
		this.uMap01.remove(spacialObj.idd);
		this.map01Size--;
	} else {
		spacialObj = this.WhichComponent();
		if (spacialObj.idd == null) {
			spacialObj.idd = addId();
		}
	}
	if (spacialObj != null) {
		this.uMap02.put(spacialObj.idd, spacialObj);
		this.map02Size++;
	}
	return spacialObj;
};
/**
* @description	returnObject   返回对象
*/
ObjectPool.prototype.returnObject = function (spacialObj) {
	if (spacialObj != null) {
		var spacialObj = this.uMap02.remove(spacialObj.idd);
		this.map02Size--;
		if (spacialObj != null) {
			this.uMap01.put(spacialObj.idd, spacialObj);
			this.map01Size++;
		}
	}
};
/**
* @description	destroy   销毁对象
*/
ObjectPool.prototype.destroy = function () {
	this.uMap01.clear();
	this.uMap02.clear();
	this.WhichComponent = null;
};
/**
* @description	fireSaturnEvent  触发事件
*/
function fireSaturnEvent(spacialObj, type, componentArr, $hI) {
	var fireArray;
	var fireComponentArray = spacialObj["_" + type];
	if (typeof (fireComponentArray) == "function") {
		fireArray = fireComponentArray(componentArr[0], componentArr[1], componentArr[2], componentArr[3], componentArr[4]);//fireArray
	} else {
		if (typeof (fireComponentArray) == "object") {
			for (var i = 0; i < fireComponentArray.length; i++) {
				var fireComponent = fireComponentArray[i];//
				fireArray = fireComponent(componentArr[0], componentArr[1], componentArr[2], componentArr[3], componentArr[4]);
				if (typeof ($hI) != "undefined" && $hI == fireArray) {
					return fireArray;
				}
			}
		}
	}
	return fireArray;
}
/**
* @description	EventManager  事件管理器
*/
var EventManager = {eventManagerArray1:null, eventManagerArray2:null, initialise:function () {
	if (this.eventManagerArray1 == null) {
		this.eventManagerArray1 = [];
		this.eventManagerArray2 = [];
		registerFinalizeProcedure(this.cleanup);
	}
}, addSaturnEvent:function (whichcomponent, type, whichFunction) {
	this.initialise();
	if (typeof (whichcomponent) == "string") {
		whichcomponent = document.getElementById(whichcomponent);
	}
	if (whichcomponent == null || whichFunction == null) {
		return false;
	}
	type = "_" + type;
	var fireComponentArray = whichcomponent[type];
	if (fireComponentArray == null) {
		whichcomponent[type] = whichFunction;
	} else {
		if (typeof (fireComponentArray) == "function") {
			var uArray1 = new Array();
			uArray1.push(fireComponentArray);
			uArray1.push(whichFunction);
			whichcomponent[type] = uArray1;
		} else {
			if (typeof (fireComponentArray) == "object") {
				fireComponentArray.push(whichFunction);
			}
		}
	}
	this.eventManagerArray2.push({whichcomponent:whichcomponent, type:type});
	return true;
}, removeSaturnEvent:function (whichcomponent, type, whichFunction) {
	this.initialise();
	if (typeof (whichcomponent) == "string") {
		whichcomponent = document.getElementById(whichcomponent);
	}
	if (whichcomponent == null) {
		return;
	}
	type = "_" + type;
	var fireComponentArray = whichcomponent[type];
	if (typeof (fireComponentArray) == "function") {
		whichcomponent[type] = null;
	} else {
		if (typeof (fireComponentArray) == "object" && whichFunction != null) {
			var i = fireComponentArray.indexOf(whichFunction);
			if (i >= 0) {
				fireComponentArray.splice(i, 1);
			}
		}
	}
}, clearSaturnEvent:function (whichcomponent, type) {
	this.initialise();
	if (typeof (whichcomponent) == "string") {
		whichcomponent = document.getElementById(whichcomponent);
	}
	if (whichcomponent == null) {
		return;
	}
	type = "_" + type;
	whichcomponent[type] = null;
}, addSystemEvent:function (whichcomponent, type, whichFunction, $M7) {
	this.initialise();
	if (typeof (whichcomponent) == "string") {
		whichcomponent = document.getElementById(whichcomponent);
	}
	if (whichcomponent == null || whichFunction == null) {
		return false;
	}
	if (whichcomponent.addEventListener) {
		whichcomponent.addEventListener(type.substring(2), whichFunction, $M7);
		this.eventManagerArray1.push({whichcomponent:whichcomponent, type:type, whichFunction:whichFunction, $M7:$M7});
		return true;
	}
	if (whichcomponent.attachEvent && whichcomponent.attachEvent(type, whichFunction)) {
		this.eventManagerArray1.push({whichcomponent:whichcomponent, type:type, whichFunction:whichFunction, $M7:false});
		return true;
	}
	return false;
}, removeSystemEvent:function (whichcomponent, type, whichFunction, $M7) {
	this.initialise();
	if (typeof (whichcomponent) == "string") {
		whichcomponent = document.getElementById(whichcomponent);
	}
	if (whichcomponent == null || whichFunction == null) {
		return;
	}
	if (whichcomponent.removeEventListener) {
		whichcomponent.removeEventListener(type.substring(2), whichFunction, $M7);
	} else {
		if (whichcomponent.detachEvent) {
			whichcomponent.detachEvent(type, whichFunction);
		}
	}
}, cleanup:function () {
    if(EventManager.eventManagerArray1)
	for (var i = 0; i < EventManager.eventManagerArray1.length; i++) {
		with (EventManager.eventManagerArray1[i]) {
			if (whichcomponent.removeEventListener) {
				whichcomponent.removeEventListener(type.substring(2), whichFunction, $M7);
			} else {
				if (whichcomponent.detachEvent) {
					whichcomponent.detachEvent(type, whichFunction);
				}
			}
		}
	}
	if(EventManager.eventManagerArray2)
	for (var i = 0; i < EventManager.eventManagerArray2.length; i++) {
		with (EventManager.eventManagerArray2[i]) {
			whichcomponent[type] = null;
		}
	}
	EventManager.eventManagerArray1 = null;
	EventManager.eventManagerArray2 = null;
}};
//form中的checkbox全选
function choose(formName){
    var formObject = document.getElementsByName(formName)[0];
    for(var i = 0 ; i<formObject.length;i++){
    	if(formObject[i].type=="checkbox"){
    	    formObject[i].checked = true;
    	}
    }
}
